#include <iostream>
#include <vector>
#include <set>
using namespace std;

char map[][5] = {"....", "....", "abc.", "def.", "ghi.", "jkl.", "mno.",
				   "pqrs", "tuv.", "wxyz"};

string char2string(char a){
	char tmp[2];
	tmp[0] = a;
	tmp[1] = '\0';
	return string(tmp);
}

vector<string> letterCombinations(string digits) {
	// Start typing your C/C++ solution below
	// DO NOT write int main() function
	vector<string> res;
	if(digits.length()==0){
		res.push_back("");
		return res;
	}
	vector<string> readv;
	vector<string> writev;
	vector<string> *pReadv = &readv;
	vector<string> *pWritev = &writev;
	// init first
	int index = digits[0] - '0';
	for(int j=0; j<4; ++j){
		if(map[index][j] != '.'){
			readv.push_back(char2string(map[index][j]));
		}
	}
	// later
	for(int i=1; i<digits.length(); ++i){
		pWritev->clear();
		index = digits[i] - '0';
		for(int j=0; j<4; ++j){
			if(map[index][j] == '.')
				continue;
			for(vector<string>::iterator it = pReadv->begin();
				it != pReadv->end();
				++it){
				string str = *it;
				str.append(char2string(map[index][j]));
				pWritev->push_back(str);
			}
		}
		vector<string> *tmp = pWritev;
		pWritev = pReadv;
		pReadv = tmp;
	}

	return *pReadv;
}

int main(){
	
	string test("23");
	vector<string> res = letterCombinations(test);

	return 0;
}
